# coding=utf-8
# 旧版本
name = "jhon"
age = 20
print("name: %s, age: %d" % (name, age))
# 使用format
print("name: {}, age: {}".format(name, age))

# 新版本
print(f"name: {name}, age: {age}")
names = ["java", "python", "c++"]
print(f"name1: {names[0]}, name2: {names[1]}, name3: {names[2]}")
# 表达式
a = 10
b = 20
print(f"a+b运算: {a + b}")
print(f"表达式运算的结果：{3 * (a + b)}")

# formatted字符串支持 =
a = 10
b = 20
print(f"{a=}, {b=}")

# 使用指定的字符填充
# 使用 * 居中填充
name = "jhon"
print("{:*^20}".format(name))
print(f"{name:*^20}")
# 使用 * 居右填充
print(f"{name:*>20}")
# 使用 * 居左填充
print(f"{name:*<20}")

# 对数值变量的格式化
price = 12.235
print("{:.2f}".format(price))
print(f"{price:.2f}")
num = 12
print(f"{num=:.1f}")
pct = 0.789
print("{:.2f}%".format(pct*100))
print(f"{pct*100:.0f}%")
